package com.loan.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TimerAspect {

    @Pointcut("@annotation(com.loan.annotation.MyTimerAnnotation)")
    public void TimerPointcut(){
    }

    //@Around("execution(* com.loan.service.impl.*.*(..))")//表达式
    @Around("TimerPointcut()")//使用注解：在需要增强的功能上添加注解
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        //记录开始时间
        Long start = System.currentTimeMillis();
        //执行连接点方法,切面所在位置对应的方法，如登录注册等
        Object result = pjp.proceed();
        //记录结束时间
        Long end = System.currentTimeMillis();
        //计算耗时
        System.out.println("耗时："+(end-start)+"mm");
        //返回连接点方法返回值
        return  result;
    }
}
